package day04;

public class Demo02 {
    public static void main(String[] args) {
        /*
         * 整数转换为7进制
         */
        int n = -200;
        String str = Integer.toString(n, 17);
        System.out.println(str);
        System.out.println(toString(n, 17));
    }
    public static final char[] DIGI = {'0','1','2','3',
            '4','5','6','7','8','9','a','b','c','d','e',
            'f','g','h','h'};
    public static String toString(int num, int radix){
        char[] chs = new char[33];
        int i = chs.length;
        boolean negative = false; //negative 负数
        if (num < 0){
            negative = true;
            num = -num;
        }
        do{
            int n = num % radix;
            char c = DIGI[n];
            chs[--i] = c;
            num /= radix;
        }while (num != 0);
        if (negative){
            chs[--i] = '-';
        }
        return new String(chs, i, chs.length-i);
    }
}
